/**
 * 获取当前用户的token
 * @returns {string | null} 返回token值，如果不存在则返回null
 */
export const getToken = (): string | null => {
  const tokenValue = localStorage.getItem('tokenValue')
  return tokenValue
}

/**
 * 获取token名称
 * @returns {string | null} 返回token名称，如果不存在则返回null
 */
export const getTokenName = (): string | null => {
  const tokenName = localStorage.getItem('tokenName')
  return tokenName || 'satoken'
}

/**
 * 设置token信息
 * @param tokenName token名称
 * @param tokenValue token值
 */
export const setToken = (tokenName: string, tokenValue: string): void => {
  localStorage.setItem('tokenName', tokenName)
  localStorage.setItem('tokenValue', tokenValue)
}

/**
 * 清除token信息
 */
export const clearToken = (): void => {
  localStorage.removeItem('tokenName')
  localStorage.removeItem('tokenValue')
  localStorage.removeItem('userId')
  localStorage.removeItem('userInfo')
}

/**
 * 检查是否已登录
 * @returns {boolean} 是否已登录
 */
export const isLoggedIn = (): boolean => {
  const tokenName = localStorage.getItem('tokenName')
  const tokenValue = localStorage.getItem('tokenValue')
  return !!(tokenName && tokenValue)
}